
local jibian = fk.CreateSkill {
  name = "lingling__jibian",
}

Fk:loadTranslationTable{
  ["lingling__jibian"] = "机变",
  [":lingling__jibian"] = "当你使用【杀】指定目标后，你可以暗中选择一项：<br>"..
  "尾袭~你对其造成1点伤害。<br>"..
  "焚营~其弃置两张牌。<br>"..
  "然后其猜测你会选择哪项，若其猜对则不执行，你摸一张牌。",

  ["#lingling__jibian-invoke"] = "机变：秘密选择一项令 %dest 猜测，猜错则执行，猜对则你摸一张牌",
  ["lingling__jibian_damage"] = "尾袭：对%dest造成1点伤害",
  ["lingling__jibian_discard"] = "焚营：%dest弃置两张牌",
  ["#lingling__jibian-choice"] = "机变：猜测 %src 的选项，猜错则执行，猜对则其摸一张牌",
}

jibian:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(jibian.name) and data.card.trueName == "slash" and
      not data.to.dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {
      choices = { "lingling__jibian_damage::"..data.to.id, "lingling__jibian_discard::"..data.to.id },
      skill_name = jibian.name,
      prompt = "#lingling__jibian-invoke::"..data.to.id,
    })
    if choice ~= "Cancel" then
      event:setCostData(self, {tos = {data.to}, choice = string.split(choice, ":")[1]})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self).choice
    local choice2 = room:askToChoice(data.to, {
      choices = { "lingling__jibian_damage::"..data.to.id, "lingling__jibian_discard::"..data.to.id },
      skill_name = jibian.name,
      prompt = "#lingling__jibian-choice:"..player.id,
    })
    if string.split(choice2, ":")[1] == choice then
      player:drawCards(1, jibian.name)
    else
      if choice == "lingling__jibian_damage" then
        room:damage{
          from = player,
          to = data.to,
          damage = 1,
          skillName = jibian.name,
        }
      else
        room:askToDiscard(data.to, {
          min_num = 2,
          max_num = 2,
          include_equip = true,
          skill_name = jibian.name,
          cancelable = false,
        })
      end
    end
  end,
})

return jibian
